﻿using Enough.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Enough.Converter
{
    /// <summary>
    /// Value converter for concerting strings to UPPERCASE
    /// </summary>
    public class WeekdayNameConverter : IValueConverter
    {
        //private static DateTimeFormatter formatter = new DateTimeFormatter(YearFormat.None, MonthFormat.None, DayFormat.None, DayOfWeekFormat.Full);
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return null;
            }
            DateTime dt;
            if (value is DateTimeOffset)
            {
                dt = ((DateTimeOffset)value).LocalDateTime;
            }
            else if (value is DateTime)
            {
                dt = (DateTime)value;
            }
            else
            {
                return value;
            }
            int currentYear = DateTime.Today.Year;
            if (dt.Year == currentYear)
            {
                int currentDay = DateTime.Today.DayOfYear;
                string key = null;
                if (dt.DayOfYear == currentDay)
                {
                    key = "Today";
                }
                else if (dt.DayOfYear == currentDay - 1)
                {
                    key = "Yesterday";
                }
                else if (dt.DayOfYear == currentDay + 1)
                {
                    key = "Tomorrow";
                }
                if (key != null)
                {
                    string translation = GlobalizationHelper.Localize(key);
                    if (string.IsNullOrEmpty(translation))
                    {
                        translation = key;
                    }
                    return translation;
                }
            }
            return dt.DayOfWeek.ToString(); //TODO
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
